﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MMS.Model;

namespace MarketMS
{
    public partial class SelectGoods : Form
    {
        public List<GoodsInfo> showDataList;
        /// <summary>
        /// 获取选中的商品数据
        /// </summary>
        public GoodsInfo SelectedGoods { get; set; }

        public SelectGoods(List<GoodsInfo> list)
        {
            InitializeComponent();
            this.showDataList = list;
        }

        private void SelectGoods_Load(object sender, EventArgs e)
        {
            dgvGoodsList.AutoGenerateColumns = false;
            //绑定数据
            dgvGoodsList.DataSource = showDataList;
        }

        private void dgvGoodsList_KeyUp(object sender, KeyEventArgs e)
        {

            //获取Enter事件
            if (e.KeyCode == Keys.Enter)
            {
                //获取选择的商品
                if (dgvGoodsList.SelectedRows.Count == 1)//判断是否选择了商品
                {
                    //获取选中行在DataGridView中是第几个
                    int index = dgvGoodsList.SelectedRows[0].Index;//行的下标从1开始
                    SelectedGoods = showDataList[index - 1];//设置选中的商品
                    this.Close();
                }
            }
        }
    }
}
